<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加人员信息</title>
    <link rel="shortcut icon" href="favicon.ico"> <link href="__PUBLIC__/Theme1/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/Theme1/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/Theme1/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="__PUBLIC__/Theme1/css/animate.min.css" rel="stylesheet">
    <link href="__PUBLIC__/Theme1/css/style.min.css?v=4.1.0" rel="stylesheet">
    <link href="__PUBLIC__/Theme1/static/plupload/upfiless.css" rel="stylesheet" type="text/css" />
    <link href="__PUBLIC__/Theme1/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
    <link href="__PUBLIC__/Theme1/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="__PUBLIC__/Theme1/css/newstyle.css" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>添加人员信息 <a href="__URL__/lists" style="margin-left:15px; color:#06cbc4">考勤列表</a></h5>
                        <div class="ibox-tools">
                            
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form method="post" action="__URL__/AddKaoqin" class="form-horizontal" id="form-add" enctype="multipart/form-data">
							<div class="form-group">
                                 <label class="col-sm-3 control-label">说明：姓名和身份证号只用输入一个即可</label>
                            </div>
    
                          <div class="form-group">
                                 <label class="col-sm-1 control-label">姓名</label>
                                <div class="col-sm-3">
                                    <input type="text" name="stName" id="stName" class="form-control">
                                </div>
                                <label class="col-sm-1 control-label">身份证号</label>
                                <div class="col-sm-3">
                                    <input type="text" name="stIDCard" id="stIDCard" value="" placeholder="请输入身份证号" class="form-control">
                                </div>
                            </div>
							
                           <div class="form-group">
                                <label class="col-sm-1 control-label">考勤类型</label>
								<div class="col-sm-3">
                                   <select class="chosen-select form-control" size="1"
										name="kabout" id="kabout" required>
										<option value="">请选择类型</option>
										<foreach name="kabout" item="valkabout" key="kaboutk">
										<option value="<{$kaboutk}>"><{$valkabout}></option>
										</foreach>
									</select> 
								</div>

                                <label class="col-sm-1 control-label">是否补打考勤</label>
                                <div class="col-sm-3">
                                
                                    <label class="checkbox-inline">
                                        <input type="radio" value="0" name="kType" id="kType" checked>否</label>
                                    <if condition="(session('aPowers') lt 2)">
                                        <label class="checkbox-inline">
                                        <input type="radio" value="1" name="kType" id="kType" >是</label>
                                    </if>
                                </div>
							</div>

							<div class="form-group" style="display:none" id="budadiv">
							    <label class="col-sm-1 control-label">补打时间</label>
                                    <div class="col-sm-2" style="width:15%">
                                        <input type="date" name="date" id="date" class="form-control">
                                    </div>
									<div class="col-sm-2" style="width:10%">
                                        <input type="time" name="time" id="time" class="form-control">
                                    </div>
									
                                <label class="col-sm-1 control-label">补打原因</label>
                                <div class="col-sm-3">
                                    <input type="text" name="reason" id="reason"  placeholder="请填写补打考勤原因" class="form-control">
                                </div>
							</div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label">地区人员</label>
                                <div class="col-sm-7" >
                                    <select class="selectRegione"  name="regione1" >
                                        <php>
                                            if(count($regione1)>1){
                                            echo "<option value='0'>请选择</option>";
                                            }
                                        </php>
                                        <foreach name="regione1" item="val" key="k">
                                            <option value="<{$val.id}>" ><{$val.name}></option>
                                        </foreach>
                                    </select>

                                    <select class="selectRegione"  name="regione2" <php>if(empty($regione2)){</php>style="display: none"<php>}</php> >
                                    <php>if(empty($regione2)){</php>
                                    <option value="0">请选择</option>
                                    <php>}else{
                                        if(count($regione2)>1){
                                        echo "<option value='0'>请选择</option>";
                                        }
                                    </php>
                                    <foreach name="regione2" item="val" key="k">
                                        <option value="<{$val.id}>" ><{$val.name}></option>
                                    </foreach>
                                    <php>}</php>
                                    </select>

                                    <select class="selectRegione"  name="regione3" <php>if(empty($regione3)){</php>style="display: none"<php>}</php> >
                                    <php>if(empty($regione3)){</php>
                                    <option value="0">请选择</option>
                                    <php>}else{
                                        if(count($regione3)>1){
                                        echo "<option value='0'>请选择</option>";
                                        }
                                    </php>
                                    <foreach name="regione3" item="val" key="k">
                                        <option value="<{$val.id}>" ><{$val.name}></option>
                                    </foreach>
                                    <php>}</php>
                                    </select>

                                    <select class="selectRegione"  name="regione4" <php>if(empty($regione4)){</php>style="display: none"<php>}</php> >
                                    <php>if(empty($regione4)){</php>
                                    <option value="0">请选择</option>
                                    <php>}else{
                                        if(count($regione4)>1){
                                        echo "<option value='0'>请选择</option>";
                                        }
                                    </php>
                                    <foreach name="regione4" item="val" key="k">
                                        <option value="<{$val.id}>" ><{$val.name}></option>
                                    </foreach>
                                    <php>}</php>
                                    </select>
                                    <!--小组-->
                                    <select class="selectRegione"  name="xiaozu" <php>if(empty($xiaozulist)){</php>style="display: none"<php>}</php> >
                                    <php>if(empty($xiaozulist)){</php>
                                    <option value="0">请选择</option>
                                    <php>}else{
                                        if(count($xiaozulist)>1){
                                        echo "<option value='0'>请选择</option>";
                                        }
                                    </php>
                                    <foreach name="xiaozulist" item="val" key="k">
                                        <option value="<{$val.dId}>" <if condition="$val.dId eq $xiaozu">selected = "selected"</if> ><{$val.dName}></option>
                                    </foreach>
                                    <php>}</php>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group" id="userListTable" style="    padding-left: 7%;">

                                <foreach name="xiaozulist" item="val" key="key">
                                    <php>$xiaozuusers=$userlist[$key];if(!empty($xiaozuusers)){</php>
                                    <ul class="choiceUserTable" id="xiaozu<{$val.dId}>">
                                            <li class="xiaozuLi"><{$val.dName}>:</li>
                                            <foreach name="xiaozuusers" item="v" key="k">
                                                <li><input type="checkbox"  name="userlist[]" value="<{$v.stId}>"/><{$v.stName}></li>
                                            </foreach>
                                        <div  class='clearBoth'></div>
                                    </ul>
                                    <php>}</php>
                                </foreach>


                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="button" id="submitButton">添加考勤</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="__PUBLIC__/Theme1/js/jquery.min.js?v=2.1.4"></script>
    <script src="__PUBLIC__/Theme1/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="__PUBLIC__/Theme1/js/content.min.js?v=1.0.0"></script>
    <script src="__PUBLIC__/Theme1/js/plugins/iCheck/icheck.min.js"></script>

<script type="text/javascript" src="__PUBLIC__/Theme1/check/js/jquery.validate.min.js"></script> 

<script type="text/javascript" src="__PUBLIC__/Theme1/check/js/messages_zh.min.js"></script> 

<script type="text/javascript" src="__PUBLIC__/Theme1/check/js/validate-methods.js"></script> 
<script type="text/javascript" src="__PUBLIC__/Theme1/lib/webuploader/0.1.5/webuploader.min.js"></script> 

    <script>
        $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});
    </script>
    
    <script type="text/javascript">
</script> 
    
<script type="text/javascript" src="__PUBLIC__/Theme1/static/plupload/plupload.full.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(){

		$("input[name=kType]").each(function(){
        $(this).click(function(){
            if($(this).val()=='1'){
				$("#budadiv").show();
			}else
				$("#budadiv").hide();
        });
    });

        $("#submitButton").click(function(){
            $("#submitButton").attr("disabled","disabled");
            var date= $("#form-add").serialize();
            $.ajax({    //ajax方法获取选定区域的下级区域列表
                url:"/Personnelsystem/Kaoqin/AddKaoqin",
                data:date,
                dataType:'json',
                type:'post',
                success:function(re){
                    if(re.error){
                        alert(re.msg);
                        $("#submitButton").removeAttr("disabled");
                    }else if(re.error==0){
                        alert("打考勤成功");
                        $("#stName").val("");
                        $("#stIDCard").val("");
                        $("#submitButton").removeAttr("disabled");
                    }
                }
            })
        });

        //当第一个选择时，给第二填充数据
        $("[name='regione1']").change(function(){
            $("[name='regione2']").html('<option value="0">加载中...</option>');
            var id=$(this).val();
            var html='<option value="0">请选择</option>';
            $.ajax({    //ajax方法获取选定区域的下级区域列表
                url:"/Personnelsystem/Department/getChildId",
                data:{id:id},
                dataType:'json',
                type:'post',
                success:function(re){
                    var html='<option value="0">请选择</option>';
                    var item=re;
                    for(var i in item){
                        html +='<option value="'+item[i]['id']+'" >'+item[i]['name']+'</option>';
                    }
                    $("[name='regione2']").html(html);
                    $("[name='regione2']").show();
                }
            })
        });
        //当第2个选择时，给第3填充数据
        $("[name='regione2']").change(function(){
            $("[name='regione3']").html('<option value="0">加载中...</option>');
            var id=$(this).val();
            var html='<option value="0">请选择</option>';
            $.ajax({    //ajax方法获取选定区域的下级区域列表
                url:"/Personnelsystem/Department/getChildId",
                data:{id:id},
                dataType:'json',
                type:'post',
                success:function(re){
                    var html='<option value="0">请选择</option>';
                    var item=re;
                    for(var i in item){
                        html +='<option value="'+item[i]['id']+'" >'+item[i]['name']+'</option>';
                    }
                    $("[name='regione3']").html(html);
                    $("[name='regione3']").show();
                }
            })
        });
        //当第3个选择时，给第4填充数据
        $("[name='regione3']").change(function(){
            $("[name='regione4']").html('<option value="0">加载中...</option>');
            var id=$(this).val();
            var html='<option value="0">请选择</option>';
            $.ajax({    //ajax方法获取选定区域的下级区域列表
                url:"/Personnelsystem/Department/getChildId",
                data:{id:id},
                dataType:'json',
                type:'post',
                success:function(re){
                    var html='<option value="0">请选择</option>';
                    var item=re;
                    for(var i in item){
                        html +='<option value="'+item[i]['id']+'" >'+item[i]['name']+'</option>';
                    }
                    $("[name='regione4']").html(html);
                    $("[name='regione4']").show();
                }
            })
        });

        //当选择村时，获取组信息
        $("[name='regione4']").change(function(){
            $("[name='xiaozu']").html('<option value="0">加载中...</option>');
            var id=$(this).val();
            var html='<option value="0">请选择</option>';
            $.ajax({    //ajax方法获取选定区域的下级区域列表
                url:"/Personnelsystem/Staff/getxiaozuInfo",
                data:{id:id},
                dataType:'json',
                type:'post',
                success:function(re){
                    var html='<option value="0">请选择</option>';
                    var item=re;
                    for(var i in item){
                        html +='<option value="'+item[i]['dId']+'" >'+item[i]['dName']+'</option>';
                    }
                    $("[name='xiaozu']").html(html);
                    $("[name='xiaozu']").show();
                }
            });
            $.ajax({    //ajax方法获取选定区域的下级区域列表
                url:"/Personnelsystem/Kaoqin/getuserlist",
                data:{id:id},
                dataType:'json',
                type:'post',
                success:function(re){
                    $("#userListTable").html();
                    var html="";
                    $.each(re.xiaozulist, function(idx, obj) {
                        var xiaozuUser=re.userlist[idx];
                        if(xiaozuUser){
                            html+="<ul class='choiceUserTable' id='xiaozu"+obj.dId+"'>";
                            html+="<li class='xiaozuLi'>"+obj.dName+":</li>";

                            $.each(xiaozuUser, function(key, val) {
                                html+="<li><input type='checkbox'  name='userlist[]' value='"+val.stId+"'/>"+val.stName+"</li>";
                            });
                        }
                        html+="<div class='clearBoth'></div></ul>";
                    });
                    $("#userListTable").html(html);
                }
            });
        });

        //当选择小组时，隐藏多余信息
        $("[name='xiaozu']").change(function(){
            $("[name='userlist[]']").each(function(){
                $(this).removeAttr("checked");
            });
            var id=$(this).val();
            if(id==0){
                $('.choiceUserTable').each(function(){
                    $(this).show();
                });
            }else{
                $('.choiceUserTable').each(function(){
                    $(this).hide();
                });
                $("#xiaozu"+id).show();
            }

        });
	});
</script>  
</body>

</html>
